//
//  LGInPlaySongInfoView.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/4/7.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import UIKit

class LGInPlaySongInfoView: UIView {

    var avatarImageView:UIImageView?
    var songNameLb:UILabel?
    var artistLb:UILabel?
    var typeLb:UIButton?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.configure()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    /// 加载歌曲信息
    ///
    /// - Parameter song: 歌曲
    func loadSong(_ song:Song) -> Void {
        self.avatarImageView?.sd_setImage(with: URL.init(string: song.songPicRadio!.replacingOccurrences(of: "w_300", with: "w_500")), placeholderImage: UIImage(named:"ic_song_placeholder"))
        self.songNameLb?.text = song.songName
        self.artistLb?.text = song.artistName
        if ((song.source?.characters.count) != nil) {
//            self.typeLb?.setTitle(song.source, for: UIControlState.normal)
        }
    }

    func configure() -> Void {

        self.avatarImageView = UIImageView.init()
        self.avatarImageView?.contentMode = UIViewContentMode.scaleAspectFill
//        self.avatarImageView?.clipsToBounds = true
        self.avatarImageView?.layer.shadowOffset = CGSize.init(width: 0, height: 0)
        self.avatarImageView?.layer.shadowColor = UIColor.black.cgColor
        self.avatarImageView?.layer.shadowOpacity = 0.5
        self.avatarImageView?.layer.shadowRadius = 2
        self.addSubview(self.avatarImageView!)
        self.avatarImageView?.snp.makeConstraints({ (make) in
            make.left.equalTo(SM_SIZE(38*2))
            make.right.equalTo(SM_SIZE(-38*2))
            make.height.equalTo((self.avatarImageView?.snp.width)!)
            make.top.equalTo(0)
        })


        self.songNameLb = UILabel.init()
        self.songNameLb?.textColor = SM_HEXCOLOR("4A4A4A")
        self.songNameLb?.font = SM_CFont(24)
        self.songNameLb?.text = "无标题"
        self.addSubview(self.songNameLb!)
        self.songNameLb?.snp.makeConstraints({ (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo((self.avatarImageView?.snp.bottom)!).offset(SM_SIZE(30))
        })

        self.artistLb = UILabel.init()
        self.artistLb?.textColor = SM_HEXCOLOR("4A4A4A")
        self.artistLb?.font = SM_CFont(15)
        self.artistLb?.text = "未知人"
        self.addSubview(self.artistLb!)
        self.artistLb?.snp.makeConstraints({ (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo((self.songNameLb?.snp.bottom)!).offset(SM_SIZE(20))
            make.bottom.equalTo(0)
        })

        self.typeLb = UIButton.init()
        self.typeLb?.setTitle("K歌", for: UIControlState.normal)
        self.typeLb?.setTitleColor(SM_HEXCOLOR("#F46B37"), for: UIControlState.normal)
        self.typeLb?.contentEdgeInsets = UIEdgeInsets.init(top: SM_SIZE(1), left: SM_SIZE(4), bottom: SM_SIZE(1), right: SM_SIZE(4))
        self.typeLb?.layer.borderColor = self.typeLb?.currentTitleColor.cgColor
        self.typeLb?.layer.borderWidth = 1/UIScreen.main.scale
//        self.typeLb?.layer.cornerRadius = 2.0
//        self.typeLb?.clipsToBounds = true
        self.typeLb?.titleLabel?.font = SM_CFont(10)
        self.addSubview(self.typeLb!)
        self.typeLb?.snp.makeConstraints({ (make) in
            make.left.equalTo((self.songNameLb?.snp.right)!).offset(SM_SIZE(10))
            make.centerY.equalTo((self.songNameLb?.snp.centerY)!)
        })


    }

}
